package cn.ulyer.core.config;

import cn.ulyer.common.properties.LoginProperties;
import com.google.code.kaptcha.Producer;
import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.google.code.kaptcha.util.Config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;

@Configuration
public class KaptchaConfig {


    @Autowired
    private LoginProperties loginProperties;


    @Bean
    public Producer producer() {
        DefaultKaptcha producer = new DefaultKaptcha();
        Properties properties = new Properties();
        properties.put("kaptcha.image.width",loginProperties.getCodeImgWidth());
        properties.put("kaptcha.image.height",loginProperties.getCodeImgHeight());
        properties.put("kaptcha.textproducer.char.string",loginProperties.getVerifyCodeChars());
        properties.put("kaptcha.textproducer.char.length",loginProperties.getVerifyCodeLength());
        Config config = new Config(properties);
        producer.setConfig(config);
        return producer;
    }


}
